﻿using Abp.Application.Services;
using Mall.DomainModel;
using Mall.DomainModel.Dto.Query;
using Mall.Service.Dto;
using System.Text;

namespace Mall.Service
{
    public class ShipperManageUserService: ApplicationService, IShipperManageUserService
    {
        private readonly IShipperManageUserRepository _shipperManageUserRepository;

        public ShipperManageUserService(IShipperManageUserRepository shipperManageUserRepository)
        {
            _shipperManageUserRepository = shipperManageUserRepository;
        }

        public async Task<ShipperManageUserOutput> GetList(ShipperManageUserQueryInput query)
        {
            var list = await _shipperManageUserRepository.GetList(query);
            var output = new ShipperManageUserOutput
            {
                 Items = list.Item1.Select(x => new ShipperPreOrderDto
                 {
                     Id= x.Id,
                     RealName= x.RealName,
                     Phone= x.Phone,
                     RoleNames = x.RoleNames,
                     UserName = x.UserName,
                     Password = x.Password,
                     IsEnabled = x.IsEnabled,
                     EditPassWordTime = x.EditPassWordTime!=null ? x.EditPassWordTime :null
                 }).ToList(),
                 TotalCount= list.Item2
            };
            return output;
        }

        public async Task<bool> Add(ShipperManageUser user)
        {
            var input= await _shipperManageUserRepository.Add(user);
            return input;
        }
        public async Task<bool> Update(ShipperManageUser user)
        {
            var input = await _shipperManageUserRepository.Update(user);
            return input;
        }
    }
}
